import { Component, OnInit, AfterViewInit } from '@angular/core';
import * as $ from 'jquery' ;
import { MainService } from '../../service/main.service';
import { Router, Params } from '@angular/router';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit,AfterViewInit {
  a:Swiper
  b:Swiper
  slides
  
  gsxwData=[];
  gsjjData=[];
  gsxwImg='';
  firstTitle;
  firstId;
  contentTitle;
  contentCt;
homeFirstList;
secondId
gsjjImg;
gsjjContent;
control:boolean
mainUrl
branchList
linkList
gsyjlbt



  constructor(private service:MainService,private route:Router) {
this.mainUrl=service.picUrl
    this.control=true;
    this.service.getFromServ('/api/index/get_index',{},res=>{

      this.gsxwData=res.data.company
      this.gsxwImg=this.mainUrl+res.data.company[0].image
      console.log(res);
      this.firstTitle=res.data.company[0].title
      this.firstId=res.data.company[0].id; 
      this.secondId=res.data.company[1].id; 
      this.homeFirstList=res.data.company.slice(2);
      this.contentCt= res.data.company[1].content.substring(0,60);
      // $('.topContent').html(this.contentCt);
      this.contentTitle=res.data.company[1].title
      console.log(this.homeFirstList);
      this.gsjjImg=service.mainUrl+ res.data.suggest[0].image
      // this.gsjjContent=res.data.suggest[0].content;
      $('.gsjjContent').append('&nbsp;&nbsp;'+res.data.suggest[0].content.substring(5,190)+'...')
      
      },err=>{
      
      })

      this.service.getFromServ('/api/index/get_branch',{},res=>{
        console.log(res);
        this.branchList = res.list;

        
      },err=>{})

      this.service.getFromServ('/api/index/get_link',{},res=>{
        console.log(res);
        this.linkList = res.list;
      },err=>{})

   }

  ngOnInit() {
    
  }
 
  ngAfterViewInit(){
    // 科技创新轮播图
this.service.getFromServ('/api/banner/get_science',{},res=>{
  console.log(res);
 this.slides=res.data
  
},err=>{})
this.service.getFromServ('/api/banner/get_company',{},res=>{
  console.log('gsyjlbt',res);
 this.gsyjlbt=res.data
  
},err=>{})
    this.a = new Swiper('#kjcx', {
      direction: 'horizontal',
      
      observer: true, // 修改swiper自己或子元素时，自动初始化swiper
observeParents: true,   // 修改swiper父元素时，自动初始化swiper
      autoplay:{
        delay: 3000,
          // disableOnInteraction: false,
      },
      loop: false, 
      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
        type:'bullets'
      },
      // 如果需要前进后退按钮
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      }, 
      // 如果需要滚动条
      scrollbar: {
        el: '.swiper-scrollbar',
      },
    });
    this.b = new Swiper('#gsyj', {
      // direction: 'horizontal',
      
      observer: true, // 修改swiper自己或子元素时，自动初始化swiper
observeParents: true,   // 修改swiper父元素时，自动初始化swiper
      autoplay:{
        delay: 3000,
          // disableOnInteraction: false,
      },
      loop: false, 
      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
        type:'bullets'
      },
      // 如果需要前进后退按钮
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      }, 
      // 如果需要滚动条
      scrollbar: {
        el: '.swiper-scrollbar',
      },
    });
    

  }

  goToNews(arg){
    this.route.navigateByUrl('/menu/3/'+arg)
  }
  fanye(Params){
    this.b.slideTo(Params,1000)
  }

  }




